<template>
  <div class="container">
    <div style="display:flex;justify-content:flex-start;align-items:center;">
      <span>这里用来查询诗词作者信息</span>
      <el-input v-model="poetName" placeholder="请输入作者姓名" style="margin-left:20px;width:30%"></el-input>
      <el-button type="primary" style="margin-left:20px;" @click="action">查询</el-button>
    </div>
    <div style="margin-top:20px">
      <div v-html="userInfo.name" style="margin-top:10px"></div>
      <div v-html="userInfo.simpleIntro" style="margin-top:10px"></div>
      <div v-html="userInfo.detailIntro" style="margin-top:10px;white-space: pre-wrap;"></div>
    </div>
  </div>
</template>

<script>
import { getPoetInfo } from '@/common/common'

export default {
  data() {
    return {
      poetName:"",
      userInfo:{}
    }
  },
  methods:{
    action(){
      if(this.poetName == ''){
        this.$message.error("请先输入作者姓名");
        return;
      }
      let params = {
        name:this.poetName
      };
      getPoetInfo(params).then((res) => {
        if(res.status == 200){
          let content = JSON.parse(res.data.body);
          this.userInfo = content.result;
          while (this.userInfo.simpleIntro.indexOf("\\n") >= 0) { this.userInfo.simpleIntro = this.userInfo.simpleIntro.replace("\\n", " \n "); };
        }
      })
      .catch((err) => {
        console.log(err);
      })
    }
  }
}
</script>

<style>
.container {
  width: 100%;
  padding: 1%;
  margin: 0 auto;
}
</style>
